﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Configuration;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Shapes = Windows.UI.Xaml.Shapes;

namespace BoolanElement
{
    public class BooTriangle:BooTextShapesBase
    {
        Shapes.Polygon triangle;
        public Shapes.Polygon Triangle
        {
            get
            {
                return triangle;
            }
            set
            {
                triangle = value;
            }
        }

        BooTriangleElement triangleElement;
        public BooTriangleElement TriangleElement 
        {
            get { return triangleElement; }
        }

        public override BooElement Element
        {
            set { triangleElement = (BooTriangleElement)value; }
            get { return triangleElement; }
        }

        public override BooTextShapesBaseElement TextShapesBaseElement
        {
            get { return triangleElement; }
        }

        public override Shapes.Shape Shape
        {
            get { return triangle; }
        }

        public BooTriangle(BooTriangleElement element, SaveForRedoUndo saveForRedoUndo)
            : base(element)
        {
            this.triangleElement = element;
            InitOriginal();
            base.saveForRedoUndo = saveForRedoUndo;
            Focus.InitFocusEvent(this);
        }
        public BooTriangle(BooTriangleElement element)
            : base(element)
        {
            this.triangleElement = element;
            InitOriginalForThumbNails();
        }

        public override void InitShape()
        {
            triangle = new Shapes.Polygon();
            triangle.Points = BooShapesPoints.CopyPointCollection(triangleElement.Points);
            triangle.ManipulationMode = ManipulationModes.All;
        }

        public override void ReSizeUI(double x, double y)
        {
            if (triangleElement.ElementTransform.Width + x < 50 || triangleElement.ElementTransform.Height + y < 50)
            {
                return;
            }

            triangleElement.ElementTransform.Width = triangleElement.ElementTransform.Width + x;
            triangleElement.ElementTransform.Height = triangleElement.ElementTransform.Height + y;

            triangleElement.ShapeWidth = triangleElement.ElementTransform.Width;
            triangleElement.ShapeHeight = triangleElement.ElementTransform.Height;

            triangleElement.PropertyChanged("Shape");
        }

        public override void ApplySize()
        {
            base.ApplySize();
            //this.triangle.Width = triangleElement.ElementTransform.Width;
            // this.triangle.Height = triangleElement.ElementTransform.Height;

            FullGrid.Width = triangleElement.ElementTransform.Width;
            FullGrid.Height = triangleElement.ElementTransform.Height;

            //BooCanvas.Width = triangleElement.ElementTransform.Width;
            //BooCanvas.Height = triangleElement.ElementTransform.Height;

            CenterStack.Width = triangleElement.ElementTransform.Width;
            //CenterStack.MaxHeight = triangleElement.ElementTransform.Height;


            this.TextBox.Width = triangleElement.ElementTransform.Width;
            triangleElement.TextWidth = triangleElement.ElementTransform.Width;
            // this.TextBox.MaxHeight = triangleElement.ElementTransform.Height;
            // triangleElement.TextMaxHeight = triangleElement.ElementTransform.Height;

            Focus.FocusElls.ScopeRectangle.Width = triangleElement.ElementTransform.Width;
            Focus.FocusElls.ScopeRectangle.Height = triangleElement.ElementTransform.Height;
            Focus.SetFocuseEllipseMargin(triangleElement.ElementTransform.Width, triangleElement.ElementTransform.Height);

            Point[] pt = new Point[triangleElement.Points.Count];
            PointCollection pts = new PointCollection();
            triangleElement.Points.CopyTo(pt, 0);
            pt[0].X = triangleElement.ElementTransform.Width / 2;
            pt[0].Y = 0;
            pt[1].X = triangleElement.ElementTransform.Width;
            pt[1].Y = triangleElement.ElementTransform.Height;
            pt[2].X = 0;
            pt[2].Y = triangleElement.ElementTransform.Height;
            pts.Add(pt[0]);
            pts.Add(pt[1]);
            pts.Add(pt[2]);
            triangle.Points = pts;
            triangleElement.Points = pts;
        }

        public override void ReMargin(double x, double y)
        {
            this.Element.ElementTransform.Translate.X += x;
            this.Element.ElementTransform.Translate.Y += y;
        }

    }
}
